﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Security.Principal;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Reporting.WebForms;

namespace UCWebpart.Admin
{
    public partial class reports : System.Web.UI.Page
    {
        string url = "/PRD/VenueBooking/场地使用记录查询";
        string SSRSAccount = "mespublisher";
        string SSRSPassword = "mes_2011";
        string SSRSServerUrl = "http://szapp06.gwkf.cn:888/ReportServer";
        string SSRSDomain = "GWKF";

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.ReportViewer1.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;
                this.ReportViewer1.ServerReport.ReportServerUrl = new System.Uri(SSRSServerUrl);

                ReportViewerCredentials.MyReportViewerCredential rvc = new ReportViewerCredentials.MyReportViewerCredential
                (SSRSAccount, SSRSPassword, SSRSDomain);
                ReportViewer1.ServerReport.ReportServerCredentials = rvc;
                //ReportViewer1.ServerReport.ReportPath = TreeViewNavigator.SelectedNode.Value.ToString();
                ReportViewer1.ServerReport.ReportPath = url;
                ReportViewer1.ZoomMode = ZoomMode.Percent;
                ReportViewer1.ServerReport.Refresh();
            }
        }

        public class ReportViewerCredentials
        {
            public class MyReportViewerCredential : IReportServerCredentials
            {
                private string _username;
                private string _password;
                private string _domain;
                public Uri ReportServerUrl;
                public MyReportViewerCredential(string username, string password, string domain)
                {
                    _username = username;
                    _password = password;
                    _domain = domain;
                }
                public WindowsIdentity ImpersonationUser
                {
                    get
                    {
                        return null;
                    }
                }

                public System.Net.ICredentials NetworkCredentials
                {
                    get
                    {
                        return new NetworkCredential(_username, _password, _domain);
                    }
                }

                public bool GetFormsCredentials(out Cookie authCookie,
                    out string user, out string password, out string authority)
                {
                    authCookie = null;
                    user = _username;
                    password = _password;
                    authority = _domain;
                    return false;
                }
            }
        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            ReportViewerCredentials.MyReportViewerCredential rvc = new ReportViewerCredentials.MyReportViewerCredential
          (SSRSAccount, SSRSPassword, SSRSDomain);
            ReportViewer1.ServerReport.ReportServerCredentials = rvc;
            ReportViewer1.ServerReport.ReportPath = DropDownList1.SelectedValue.ToString();
        }

    }
}